package Year2021.month10.Day21;

public class Market {
    String name;
    String address;//地址

    public void show1() {
        System.out.println("这个超市的名字是" + name + "\t" + "地址是在" + address);
    }


    //定义会员数组
    Member member[] = new Member[100];
    int k = 0;
    int i = 0;

    //添加新会员；
    public void add(String newName, int memberNumber, String phoneNumber, int integral) {
        for (i = k; i < member.length; i++) {
            member[i] = new Member();
            if (member[i].name == null) {
                member[i].name = newName;
                member[i].memberNumber = memberNumber;
                member[i].phoneNumber = phoneNumber;
                member[i].integral = integral;
                k++;
                break;

            }

        }
    }

    boolean checkCardNoRepeat(int memberNumber) {
        for (int j = i; j < member.length; j++) {
            if ((member[i] != null) && (member[i].memberNumber == member[j].memberNumber)) {
                System.out.println("会员卡号重复，禁止添加，请重新输入");
                return true;
            }
        }
        return false;
    }


    //会员信息展示；
    public void show() {
        for (int i = 0; i < member.length; i++) {
            if (member[i] == null) {
            } else {
                System.out.println("这个会员叫" + member[i].name + ",会员号是" + member[i].memberNumber +
                        ",手机号是" + member[i].phoneNumber + ",会员卡里的积分还有" + member[i].integral
                        + "分");
            }
        }
    }

    //涨积分；
    boolean inc(String cardNo, int fen) {
        for (int i = 0; i < member.length; i++) {
            if (member[i] != null && member[i].name.equals(cardNo)) {
                member[i].integral += fen;
                System.out.println("会员涨分后的积分为" + member[i].integral + "分");
                return true;
            }

        }
        return false;


    }

    //兑换礼品；
    int fIntegarl = 0;//剩余积分；

    public String duihuan(int cardNO, int lipingleixing) {
        if (cardNO != member[i].memberNumber) {
            return null;
        } else {
            if (lipingleixing == 1) {
                if (member[i].integral-100>= 0) {
                    fIntegarl = member[i].integral - 100;
                    System.out.println("兑换成功，剩余积分为" + fIntegarl + "分");
                } else {
                    System.out.println("积分不够，兑换失败");
                    return null;
                }
            } else if (lipingleixing == 2) {
                if (member[i].integral-400 >= 0) {
                    fIntegarl = member[i].integral - 400;
                    System.out.println("兑换成功，剩余积分为" + fIntegarl + "分");
                } else {
                    System.out.println("积分不够，兑换失败");
                    return null;
                }
            } else if (lipingleixing == 3) {
                if (member[i].integral-1000 >= 0) {
                    fIntegarl = member[i].integral - 1000;
                    System.out.println("兑换成功，剩余积分为" + fIntegarl + "分");
                } else {
                    System.out.println("积分不够，兑换失败");
                    return null;
                }
            }
        }return null;
    }
}


